package bootstrap

import (
	"fmt"
	"gitee.com/yuya000/cards-game-server-go/niuniu"
	"gitee.com/yuya000/cards-game-server-go/paodekuai"
	"gitee.com/yuya000/cards-game-server-go/server"
	"github.com/lytics/logrus"
	"os"
)

func usage() {
	fmt.Println("Usage:\n")
	fmt.Println("/cards-game-server-go cards-game-server.toml")
}

func Start() error {
	if len(os.Args) != 2 {
		usage()
		logrus.Fatalln("参数错误!!")
	}
	logrus.Println("加载配置文件")
	if err := server.LoadConfigurationFromFile(os.Args[1]); err != nil {
		logrus.Fatalln(err)
	}

	logrus.Println("安装游戏 [牛牛]")
	server.SetupGame(niuniu.GameName, &niuniu.NiuNiuFactory{})

	logrus.Println("安装游戏 [跑得快]")
	server.SetupGame(paodekuai.GameName, &paodekuai.PaoDeKuaiFactory{})

	logrus.Println("启动服务")
	if err := server.Start(); err != nil {
		logrus.Fatalln(err)
	}
	return nil
}
